Skip to main content

Tushare Financial Data Interfaces II Introduction to Common Data Interfaces

· 7 Minutes to read
Allen Ma

Macroeconomic data

A wide range of domestic macroeconomic data can be obtained from the Tushare platform using Tushare's built-in functions, such as money supply, reserve requirement ratio, deposit and loan rates, GDP, consumer price index and ex-factory industrial price index for multiple periods.

在这里插入图片描述

Money supply

The ts.get_money_supply() function allows you to obtain data on our money supply for each of the last 30 years.

import tushare as  ts
df = ts.get_money_supply()
df.head()
df.columns

在这里插入图片描述 Return value description.

ParameterExplanation
monthStatistics time
m2Monetary and quasi-monetary (broad money M2) (billion yuan)
m2_yoyMonetary and quasi-monetary (broad money M2) year-on-year growth (%)
m1Money (Narrow Money M1) (billions of yuan)
m1_yoyMoney (narrow money M1) year-on-year growth (%)
m0Cash in circulation (M0) ($bn)
m0_yoyCash in circulation (M0) year-on-year growth (%)
cdDemand deposits ($bn)
cd_yoyDemand deposits growth (%)
qmQuasi-currency ($bn)
qm_yoyQuasi-currency growth (%)
ftdTime deposits ($bn)
ftd_yoyYear-on-year growth in time deposits (%)
sdSavings deposits ($bn)
sd_yoySavings deposits growth (%)
restsOther deposits ($bn)
rests_yoyYear-on-year growth in other deposits (%)

Deposit rates and loan rates

Tushare provides corresponding interface functions for different types of interest rates in order for developers to obtain the required interest rate data. The deposit rate function get_deposit_rate() and the loan rate function get_loan_rate() can be used to obtain the deposit rate and loan rate data issued by the People's Bank of China since 1989 respectively.

import tushare as  ts
df = ts. get_loan_rate()
df.head()

在这里插入图片描述 在这里插入图片描述

Shibor Rate

The Shanghai Interbank Offered Rate (Shibor) is the arithmetic average of the RMB interbank offered rates calculated and determined by a quotation group of banks with high credit ratings, using the National Interbank Offered Rate Centre in Shanghai as the technical platform to calculate, publish and name the rate.

import tushare as  ts
pro = ts.pro_api('用户tushare token')
df=pro.shibor()
df.head()

在这里插入图片描述 Other interest rate pro interface functions. (1) pro.shibor_quote():Shibor quoted data (2) pro.shibor_lpr():LPR lending base rate (3) pro.libor():LIBOR (4) pro.Hibor():Hong Kong Interbank Offered Rate

Stock Quote Data

From the Tushare platform, users can access the stock trading data of all listed companies on the Shanghai Stock Exchange and Shenzhen Stock Exchange, as well as the data of various stock indices (e.g. SSE Composite Index, SZSE Component Index, GEM Index, CSI 300 Index and SMB Index, etc.) of these two markets. The following commands can be executed in sequence to obtain historical daily ticker data for stock code 600848.

import  tushare  as  ts
df = ts.get_hist_data('600848', ktype = 'D')
df.head()

在这里插入图片描述在这里插入图片描述 Return value description.

ParameterExplanation
dateDate
openOpening price
highHighest price
closeClosing price
lowLowest price
volumevolume
price_changeprice change
p_changeprice_change
ma55-day average
ma1010 Day Average
ma2020 Day Average
v_ma55-day average volume
v_ma1010 Day Average
v_ma2020 Day Average
turnoverturnover

The Tushare package provides a number of pro interface functions to return historical stock data. Registered users of the platform can use the pro interface functions to obtain stock quotes, but most of the pro interface functions require users to have a certain number of points before they can be called. The operation of the pro interface function to obtain daily stock quotes is as follows.

import tushare as  ts
pro = ts.pro_api()
df = pro.daily(ts_code = '600008.SH', start_date = '20000501', end_date = '20190808')
df.head()

在这里插入图片描述 There are some structural differences between the quotation data obtained with the pro interface function pro.daily() and the quotation data obtained with the get_hist_data() function. The return data from the pro.daily() function uses the default index, with the date of the transaction as a field (column) data item, whereas the return data from the get_hist_data() function uses the date of the transaction as an index. Given that the structure of the data returned by the different interface functions differs to a greater or lesser extent, it is important to design programs that process this data in such a way that the appropriate processing method is chosen based on the structure of the data returned, or that the data items returned are modified as necessary to meet the formatting requirements of other data processing statements.

在这里插入图片描述 Tushare also provides real-time data on stock trading quotes, i.e. data on the prices of stocks that are being traded on that day. For example, the real time stock trading data obtained through the get_realtime_quotes() function can include information such as the list of quotes and transaction prices of the stock at the current moment, the five buy quotes and five sell prices and other data items, with a total of more than 30 items of information. The operation process is as follows.

import tushare as  ts
df = ts.get_realtime_quotes('300274')
df[['code','name','price','bid','ask','volume','amount','time']]

在这里插入图片描述 Partial return value description.

ParameterExplanation
codeStock code
nameName of the stock
priceCurrent price
highToday's high price
lowToday's low price
bidThe bid price, i.e. "buy one" offer
askbid to sell, i.e. "sell one" offer
volumevolume maybe you need do volume/100 amount, amount traded ($ CNY)

Fundamental data of listed companies

The Tushare platform provides fundamental data on listed companies, including financial position, profitability, market share, management structure, talent composition and more. In addition to stock price data, financial analysts often need fundamental data on listed companies to understand the value of a company's investment. Tushare provides the interface functions for listed companies' fundamental data as shown in the table. 在这里插入图片描述

Stock Index Data

A stock index is a composite price value of stocks compiled by a stock exchange or financial services institution that reflects the price movements of a particular group (class) of stocks.

Stock exchanges and some financial services institutions have compiled and publicly released dozens of stock price indices, and stock investors are accustomed to using stock indices as an observational indicator of stock market price movements.

The pro.index_basic () function can be used to obtain the various stock indices published by the SSE.

import  tushare  as  ts
pro = ts.pro_api('用户tushare token')
df = pro.index_basic(market = 'SSE')
df.head()

在这里插入图片描述 The following two tables list the input and output parameters of the Tushare platform pro version interface function index_basic().

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述